package com.iot.ic.common.config;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource(value = "classpath:znjj.properties", ignoreResourceNotFound = true)
public class GlobalConfig {
    /**
     * 当前对象实例
     */
    private final static GlobalConfig global = new GlobalConfig();

    /**
     * 保存全局属性值
     */
    private final static Map<String, String> map = new HashMap();

    /**
     * 获取当前对象实例
     */
    public static GlobalConfig getInstance() {
        return global;
    }

    private static PropertiesLoader loader = new PropertiesLoader("znjj.properties");

    public static String getConfig(String key) {
        String value = map.get(key);
        if (value == null) {
            value = loader.getProperty(key);
            map.put(key, value != null ? value : StringUtils.EMPTY);
        }
        return value;
    }


}
